package com.hexiang.spock

import org.junit.runner.RunWith
import org.mockito.Mockito
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PowerMockIgnore
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import org.powermock.modules.junit4.PowerMockRunnerDelegate
import org.spockframework.runtime.Sputnik
import spock.lang.Specification
import spock.lang.Unroll

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(Sputnik.class)
@PrepareForTest([StateHolder])
@PowerMockIgnore(["org.w3c.dom.*", "javax.xml.*", "org.xml.*"])
class StateHolderTest extends Specification {


    @Unroll
    def "getState"() {
        setup:
        StateHolder stateHolder = PowerMockito.mock(StateHolder.class)
        PowerMockito.when(stateHolder,"getState").thenCallRealMethod()
        PowerMockito.when(stateHolder,"innerMethod",Mockito.any()).thenReturn("hello")

        when:
        String ret = stateHolder.getState()

        then:
        ret == "hello"
    }
}
